// MayBe函子：可以对外部的空值情况做处理
// 处理Functor函子出现null，undefined的情况

class MayBe {
    static of(value) {
        return new MayBe(value)
    }
    constructor(value) {
        this._value = value
    }
    map(fn) {
        return this.inNothing() ? MayBe.of(null) : MayBe.of(fn(this._value))
    }
    inNothing() {
        return this._value === null || this._value === undefined
    }
}

const r = MayBe.of('hello world')
    .map(x => x.toUpperCase())
    .map(x => null)
    .map(x => x.split('_'))
console.log(r);



